﻿using RBOSS.Business.AdminModule;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace RBOSS.WebUI
{
    public partial class Adminhome : System.Web.UI.Page
    {
      //  private RBOSSEntities rb = new RBOSSEntities();
        User_sys us = new User_sys();
        protected void Page_Load(object sender, EventArgs e)
        {

           
            if (!Page.IsPostBack)
            {
                ListItem lstItems;
                Dictionary<string, string> obj = us.getUsernames();
                foreach (string item in obj.Keys)
                {
                    lstItems = new ListItem(obj[item], item);
                    ListBox1.Items.Add(lstItems);

                    
                }

                Roles_sys Rus = new Roles_sys();
                Dictionary<string, string> roles = Rus.getRoles();
                foreach (string item in roles.Keys)
                {
                    lstItems = new ListItem(roles[item], item);
                    RolesList1.Items.Add(lstItems);
                }
            }
            
        }

        protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
           



           us= us.getuserdetail(int.Parse(ListBox1.SelectedValue));
           txtfirstname.Text = us.FirstName;
           txtlastname.Text = us.LastName;
           txtphoneNo.Text = us.PhoneNo;
           txtpostalcode.Text = us.PostalCode;
           txtprovince.Text = us.Province;
           txtemail.Text = us.Email;
           txtcountry.Text = us.Country;
           txtcity.Text = us.City;
           RolesList1.SelectedValue = us.RoleId.ToString();
        }

        protected void btnsave_Click(object sender, EventArgs e)
        {
            us.update(int.Parse(ListBox1.SelectedValue), int.Parse(RolesList1.SelectedValue), txtfirstname.Text, txtlastname.Text, txtemail.Text, txtphoneNo.Text, txtcity.Text, txtprovince.Text, txtcountry.Text, txtpostalcode.Text);
            txtfirstname.Text ="";
            txtlastname.Text = "";
            txtphoneNo.Text = "";
            txtpostalcode.Text = "";
            txtprovince.Text = "";
            txtemail.Text = "";
            txtcountry.Text = "";
            txtcity.Text = "";
            ListBox1.SelectedIndex = -1;
        }

    }
}